<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  <link rel="stylesheet" href="docgen-resources/docgen.css" type="text/css">
  <meta name="generator" content="FreeMarker Docgen (DocBook 5)">
  <title>
    FreeMarker Manual - Multithreading
  </title>
    <script type="text/javascript" src="docgen-resources/jquery.js"></script>
    <script type="text/javascript" src="docgen-resources/linktargetmarker.js"></script>
</head>
<body>

    <div class="navigation">
    <div class="breadcrumb">
<span class="breadcrumb">        You are here:
          <a href="index.html">Book</a>
            <b>></b>
          <a href="pgui.html">Programmer's Guide</a>
            <b>></b>
          <a href="pgui_misc.html">Miscellaneous</a>
            <b>></b>
          Multithreading
</span>    </div>
    <div class="bookmarks">
<span class="bookmarks">Bookmarks:
<a href="alphaidx.html">Alpha. index</a>, <a href="gloss.html">Glossary</a>, <a href="dgui_template_exp.html#exp_cheatsheet">Expressions</a>, <a href="ref_builtins_alphaidx.html">?builtins</a>, <a href="ref_directive_alphaidx.html">#directives</a>, <a href="ref_specvar.html">.spec_vars</a>, <a href="app_faq.html">FAQ</a>, <a href="api/index.html">API</a>, <a href="../index.html">Home</a></span>    </div>
    <div class="pagers">
      <div class="pagersVerticalSpacer"><img src="docgen-resources/img/none.gif" width="1" height="1" alt="" hspace="0" vspace="0" border="0"/></div>
<div class="pagerButton"><a href="pgui_misc_beanwrapper.html"><span class="hideA">Next page: </span>Bean wrapper</a></div><div class="pagerButton"><a href="pgui_misc_charset.html">Previous page</a></div><div class="pagerButton"><a href="pgui_misc.html">Parent page</a></div><div class="pagerButton"><a href="index.html">Contents</a></div>      <div class="pagersVerticalSpacer"><img src="docgen-resources/img/none.gif" width="1" height="1" alt="" hspace="0" vspace="0" border="0"/></div>
    </div>
    </div>

<div id="mainContent">

  
  
  
  
  <h1 class="rank_section1"
        id="pageTopTitle">
<a name="pgui_misc_multithreading"></a>Multithreading  </h1>
    
    
<p>In a multithreaded environment <tt style="color: #A03D10">Configuration</tt>
        instances, <tt style="color: #A03D10">Template</tt> instances and data-models
        should be handled as immutable (read-only) objects. That is, you
        create and initialize them (for example with
        <tt style="color: #A03D10">set<i style="color: #DD4400">...</i></tt> methods), and
        then you don't modify them later (e.g. you don't call
        <tt style="color: #A03D10">set<i style="color: #DD4400">...</i></tt>). This allows us
        to avoid expensive synchronized blocks in a multithreaded environment.
        Beware with <tt style="color: #A03D10">Template</tt> instances; when you get a
        <tt style="color: #A03D10">Template</tt> instance with
        <tt style="color: #A03D10">Configuration.getTemplate</tt>, you may get an instance
        from the template cache that is already used by other threads, so do
        not call its <tt style="color: #A03D10">set<i style="color: #DD4400">...</i></tt>
        methods (calling <tt style="color: #A03D10">process</tt> is of course fine).</p><p>The above restrictions do not apply if you access all objects
        from the <i>same</i> single thread only.</p><p>It is impossible to modify the data-model object or a <a href="pgui_config_sharedvariables.html">shared variable</a> with FTL,
        unless you put methods (or other objects) into the data-model that do
        that. We discourage you from writing methods that modify the
        data-model object or the shared variables. Try to use variables that
        are stored in the environment object instead (this object is created
        for a single <tt style="color: #A03D10">Template.process</tt> call to store the
        runtime state of processing), so you don't modify data that are
        possibly used by multiple threads. For more information read: <a href="pgui_misc_var.html">Variables</a></p>  
</div>

    <div class="navigation">
    <div class="pagers">
      <div class="pagersVerticalSpacer"><img src="docgen-resources/img/none.gif" width="1" height="1" alt="" hspace="0" vspace="0" border="0"/></div>
<div class="pagerButton"><a href="pgui_misc_beanwrapper.html"><span class="hideA">Next page: </span>Bean wrapper</a></div><div class="pagerButton"><a href="pgui_misc_charset.html">Previous page</a></div><div class="pagerButton"><a href="pgui_misc.html">Parent page</a></div><div class="pagerButton"><a href="index.html">Contents</a></div>      <div class="pagersVerticalSpacer"><img src="docgen-resources/img/none.gif" width="1" height="1" alt="" hspace="0" vspace="0" border="0"/></div>
    </div>
    <div class="breadcrumb">
<span class="breadcrumb">        You are here:
          <a href="index.html">Book</a>
            <b>></b>
          <a href="pgui.html">Programmer's Guide</a>
            <b>></b>
          <a href="pgui_misc.html">Miscellaneous</a>
            <b>></b>
          Multithreading
</span>    </div>
    </div>

<table border=0 cellspacing=0 cellpadding=0 width="100%">
    <tr>
      <td colspan=2><img src="docgen-resources/img/none.gif" width=1 height=8 alt=""></td>
    <tr>
      <td align="left" valign="top"><span class="smallFooter">
            FreeMarker Manual -- For FreeMarker 2.3.20
            <br>
          HTML generated: 2013-06-27 20:54:33 GMT
      </span></td>
      <td align="right" valign="top"><span class="smallFooter">
          <a href="http://www.xmlmind.com/xmleditor/">
            <img src="docgen-resources/img/xxe.gif" alt="Edited with XMLMind XML Editor">
          </a>
      </span></td>
    </tr>
</table>
  <!-- Put pre-loaded images here: -->
  <div style="display: none">
    <img src="docgen-resources/img/linktargetmarker.gif" alt="Here!" />
  </div>
</body>
</html>

